package coms.dataaccess.hibernate;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import coms.dataaccess.FileItemDAO;
import coms.datatransfer.ConferenceItemDTO;
//import coms.datatransfer.AssignedReviewDTO;
import coms.datatransfer.FileItemDTO;
import coms.exception.HibernateAccessLayerException;

public class FileItemDAOImpl extends AbstractDAO implements FileItemDAO {
	
	private FileItemDAO fileItemDAO= null;

	public void initialize(){
		fileItemDAO = new FileItemDAOImpl();
	}
	
	@Override
	public void insertFileItem(FileItemDTO fileItem) {
		Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting File Item" + fileItem.getFileID());
		System.out.println("inside file dao");
		super.saveOrUpdate(fileItem);
		}

	@Override
	public void updateFileItem(FileItemDTO fileItem) {
		Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating File Item" + fileItem.getFileID());
		super.saveOrUpdate(fileItem);
	}

	@Override
	public void deleteFileItem(int fileItemID) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public FileItemDTO findFileItemById(int fileItemID) {
		// TODO Auto-generated method stub
		
		ArrayList<FileItemDTO> listFileItems = (ArrayList<FileItemDTO>)super.findByCategory(FileItemDTO.class, "fileID", Integer.toString(fileItemID));
		System.out.println("size is"+ listFileItems.size());
		return (FileItemDTO)listFileItems.get(0);
		
	}
	@SuppressWarnings("unchecked")
	public List<Object[]> findAllConferenceItemByConfId(int ConferenceId) throws HibernateAccessLayerException {
        try {
        	List<Object[]> result = new ArrayList<Object[]>();
                  result = (List<Object[]>)super.manyToManyfindById(ConferenceItemDTO.class,"conferenceDTO", 
        			                                        "conferenceID", Integer.toString(ConferenceId));
        	System.out.println("size of confitems list"+ result.size());
        	return result;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
	
	@SuppressWarnings("unchecked")
	@Override
	public  List<Object[]> findFileByConferenceItemId(int conferenceItemId){
		
		 try {
	        	List<Object[]> result = new ArrayList<Object[]>();
	                  result = (List<Object[]>)super.manyToManyfindById(FileItemDTO.class,"conferenceItemDTO", 
	        			                                        "conferenceItemID", Integer.toString(conferenceItemId));
	        	System.out.println("size of confitems list"+ result.size());
	        	return result;
	        	
	        } catch (Throwable t) {
	            throw new HibernateAccessLayerException(t.toString());
	        }
	}

}
